<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link href="/erp/assets/css/bootstrap.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="/erp/css/style.css"/>
    <link rel="stylesheet" href="/erp/assets/css/ace.min.css"/>
    <link rel="stylesheet" href="/erp/assets/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/erp/Widget/zTree/css/zTreeStyle/zTreeStyle.css" type="text/css">
    <link href="/erp/Widget/icheck/icheck.css" rel="stylesheet" type="text/css"/>
    <!--[if IE 7]>
    <link rel="stylesheet" href="/erp/assets/css/font-awesome-ie7.min.css"/>
    <![endif]-->
    <!--[if lte IE 8]>
    <link rel="stylesheet" href="/erp/assets/css/ace-ie.min.css"/>
    <![endif]-->
    <script src="/erp/js/jquery-1.9.1.min.js"></script>
    <script src="/erp/assets/js/bootstrap.min.js"></script>
    <script src="/erp/assets/js/typeahead-bs2.min.js"></script>
    <!-- page specific plugin scripts -->
    <script src="/erp/assets/js/jquery.dataTables.min.js"></script>
    <script src="/erp/assets/js/jquery.dataTables.bootstrap.js"></script>
    <script type="text/javascript" src="/erp/js/H-ui.js"></script>
    <script type="text/javascript" src="/erp/js/H-ui.admin.js"></script>
    <script src="/erp/assets/layer/layer.js" type="text/javascript"></script>
    <script src="/erp/assets/laydate/laydate.js" type="text/javascript"></script>
    <script type="text/javascript" src="/erp/Widget/zTree/js/jquery.ztree.all-3.5.min.js"></script>
    <script src="/erp/js/lrtk.js" type="text/javascript"></script>


    <title>仓库预警</title>
</head>

<body>
<div class="margin clearfix">
    <div class="Shops_Audit">
        <div class="search_style">
            <ul class="search_content clearfix">
                <li>
                    仓库名称<select class="ck" style="width: 150px; margin-left: 10px;">
                    <option value="">请选择仓库</option>
                </select>
                </li>
                <li><label class="l_f">产品名称</label><input name="pname" type="text" class="text_add" placeholder="输入产品名称"
                                                          style=" width:150px"/></li>
                <li style="width:90px;">
                    <button type="button" class="btn_search"><i class="icon-search"></i>查询</button>
                </li>
            </ul>
        </div>
    </div>
    <!--申请列表-->
    <div class="h_products_list clearfix" id="products_list">
        <div id="scrollsidebar" class="left_Treeview">
            <div class="show_btn" id="rightArrow"><span></span></div>
            <div class="widget-box side_content">
                <div class="side_title"><a title="隐藏" class="close_btn"><span></span></a></div>
                <div class="side_list">
                    <div class="widget-header header-color-green2"><h4 class="lighter smaller">现有仓库列表</h4></div>
                    <div class="widget-body">
                        <div class="widget-main padding-8">
                            <div id="treeDemo" class="ztree"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="table_menu_list" id="testIframe">
            <table class="table table-striped table-bordered table-hover" id="sample-table">
                <thead>
                <tr>
                    <!--<th width="25"><label><input type="checkbox" class="ace"><span class="lbl"></span></label></th>-->
                    <th width="60px">序号</th>
                    <th width="80px">仓库名称</th>
                    <th width="80px">产品编号</th>
                    <th width="100">产品名称</th>
                    <th width="80px">库存量</th>
                    <th width="100">状态</th>
                    <th width="100">当前产品预警值</th>
                    <th width="100">设置预警值</th>
                </tr>
                </thead>
            </table>
            <input type="hidden" id="hidden">
        </div>
    </div>
</div>
<input type="hidden" id="tj">
<input type="hidden" id="cj">
</div>
</div>
</body>
</html>
<script>
    $(function () {
        $.ajax({
            url: '/io-warehouse/warehouseAll',
            type: 'post',
            contentType: 'application/json',
            dataType: 'json',
            success: function (res) {
                for (var c in res) {
                    $(".ck").append("<option value='" + res[c].id + "'>" + res[c].warehouseName + "</option>")
                }
            }
        })

        var oTable1 = $('#sample-table').DataTable({
            "serverSide": true,     // true表示使用后台分页
            ajax: {
                "url": "/hint/hintAll",
                "type": "POST",  // 请求方式
                "dataSrc": 'data',
                data: function (d) {
                    var param = {};
                    param.draw = d.draw;
                    param.start = d.start;
                    param.length = d.length;
                    param.ck = $(".ck").val();
                    param.pname = $(".text_add").val();
                    param.cj = $("#cj").val();
                    param.tj = $("#tj").val();
                    return param;//自定义需要传递的参数。
                }
            },
            "bStateSave": true,//状态保存
            'autoWidth': true,
            "columns": [
                {
                    "data": "id"
                },
                {
                    "data": "wname"
                },
                {"data": "model"},
                {"data": "pname"},
                {"data": "pnum"},
                {
                    "data": "id",
                    "createdCell": function (td, cellData, rowData, row, col) {
                        if (rowData.pnum <= rowData.hint) {
                            $(td).empty().append('<font color="#FF0000">库存不足</font>');
                        } else {
                            $(td).empty().append('<font color="#00FF00">库存充足</font>');
                        }
                    }
                },
                {"data": "hint"},
                {
                    "data": "id",
                    "createdCell": function (td, cellData, rowData, row, col) {
                        $(td).empty().append('<button onclick="add_Click('+row+')" type="button" class="shez_id btn btn-primary"><i class="icon-edit bigger-120"></i></button>');
                    }
                }
            ]
        });

        //刷新
        $('#hidden').on('click', function () {
            console.log("test");
            oTable1.ajax.reload();
        })

        //条件查询
        $(".btn_search").click(function () {
            oTable1.ajax.reload();
        })


        /*******树状图*******/
        var setting = {
            async: {
                enable: true,
                url: "/warehouse/listTree"
            },
            view: {
                dblClickExpand: false,
                showLine: false,
                selectedMulti: false
            },
            data: {
                key: {
                    name: "name"//显示的字段
                }
            },
            callback: {
                onClick: onClick
            }
        };


        var t = $("#treeDemo");
        t = $.fn.zTree.init(t, setting);
        demoIframe = $("#testIframe");
        var zTree = $.fn.zTree.getZTreeObj("tree");

    })

    //下拉树点击节点查询数据
    function onClick(event, treeId, treeNode, clickFlag) {
        $("#cj").val(treeNode.level);
        $("#tj").val(treeNode.id);
        $(".ck").val("");
        $(".text_add").val("");

        $(".btn_search").click();
    }

    //设置预警值
    function add_Click(obj) {
        var tds = $('table tr:eq('+(obj+1)+')').find("td");
        var data = {
            id:$(tds[0]).text(),
            wname:$(tds[1]).text(),
            pname:$(tds[3]).text(),
            hint:$(tds[6]).text(),
        };
        layer.open({
            type: 2,
            title: '设置当前预警值',
            maxmin: true,
            shadeClose: true, //点击遮罩关闭层
            shade: false,
            area: ['1000px', '400px'],
            content: '/warehouse/warning/warning_addPage?'+ $.param(data),
        });
    }
</script>


<script type="text/javascript">
    //初始化宽度、高度
    $(".widget-box").height($(window).height() - 215);
    $(".table_menu_list").width($(window).width() - 260);
    $(".table_menu_list").height($(window).height() - 215);
    //当文档窗口发生改变时 触发
    $(window).resize(function () {
        $(".widget-box").height($(window).height() - 215);
        $(".table_menu_list").width($(window).width() - 260);
        $(".table_menu_list").height($(window).height() - 215);
    })


</script>
